<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <link href="../css/element.css" rel="stylesheet"/>
    <link href="../css/styleindex.css" rel="stylesheet"/>
    <link href="../css/swiper.min.css" rel="stylesheet"/>
    <style>
    .el-input__inner{
      border: 0;
      font-size: 1rem;
      text-align: center;
    }.el-input__prefix{
      display: none;
    }
    </style>
</head>
<body style="background:#EFF0F4;">

  <div class="mui-content">
    <div id="vm" class="x-examok" v-cloak>
      <div class="x-header-g" id="header">
        <a class="x-header-arrow" @click="api.closeWin()"></a>
        <div class="x-header-t">填报叫货</div>
      </div>
        <!--  -->
        <div class="">
          <template>
            <el-table :data="tabledata" @cell-click="gotrainpro">
              <el-table-column label="品名" width="90" fixed>
                <template slot-scope="scope">
                  {{scope.row.title}}
                </template>
              </el-table-column>
              <el-table-column label="存规格" width="">
                <template slot-scope="scope">
                  {{scope.row.save_unit}}
                </template>
              </el-table-column>
              <el-table-column label="计划量" width="">
                <template slot-scope="scope">
                  {{scope.row.plan_num}}
                </template>
              </el-table-column>
              <el-table-column label="叫货量" width="150">
                <template slot-scope="scope">
                  <div v-if="noget=='0'" style="border:1px solid #058142;border-radius:.2rem;"><el-input v-model="scope.row.buy_num" placeholder="请输入内容" type="number"></el-input></div>
                  <div v-else>
                    {{scope.row.buy_num}}
                  </div>
                </template>
              </el-table-column>
              <el-table-column label="单价" width="">
                <template slot-scope="scope">
                  {{scope.row.unit_price}}
                </template>
              </el-table-column>
              <el-table-column label="金额" width="">
                <template slot-scope="scope">
                  {{(scope.row.save_num*scope.row.unit_price).toFixed(2)}}
                </template>
              </el-table-column>
            </el-table>
          </template>
          <div class="x-table-desc">叫货人：{{askname}}</div>
        </div>
        <!--  -->
        <div class="x-pro-gobtn" @click="isokget" v-if="noget==0">提交</div>
        <div class="x-pro-gobtn x-disabled" v-else>已提交</div>
		  

    </div>
  </div>

  <script type="text/javascript" src="../script/vue.js"></script>
  <script type="text/javascript" src="../script/element.js"></script>
  <script type="text/javascript" src="../script/api.js"></script>
  <script type="text/javascript" src="../script/base.js"></script>
  <script type="text/javascript" src="../script/jquery-1.11.1.min.js"></script>
  <script type="text/javascript" src="../script/swiper.min.js"></script>
	<script>
apiready = function () {
    $api.fixStatusBar($api.byId('header'));
    var twsid = api.pageParam.wsid;
    console.log(twsid);

    //
    var vm = new Vue({
      el:'#vm',
      data(){
        return{
          tabsdata:'',
          curId:0,
          tabledata:[],
          cardsmonth:'',
          cardsmonthtoy:'',
          cardsmonthtom:'',
          tabsid:0,
          notkey:false,
          isfromindex:true,
          noget:0,
          askname:'',
          yesshow:false,
          noshow:false,
          isclick:true,
        }
      },
      created:function() {
        var that=this;

      },
      mounted:function(){
        var that=this;
        that.tabsid = twsid;
        //当前月份
        var date = new Date();
        var year = date.getFullYear();
        var month = date.getMonth()+1;
        var day = date.getDate();
        if(month<10){
          month = '' + 0 + month;
        }
        if(day<10){
          day = '' + 0 + day;
        }
        var toMonth = '' + year + month + day;
        that.cardsmonth = toMonth;
        that.cardsmonthtoy = year;
        that.cardsmonthtom = month;
        that.gettrainadmin()
      },
      methods: {
        //校验不为空
        isokget:function(){
          var that = this;
          // for(var i=0;i<that.tabledata.length;i++){
          //   if(that.tabledata[i].buy_num==''){
          //     api.toast({
          //         msg: '请填写叫货量',
          //         duration: 3000,
          //         location: 'bottom'
          //     });
          //     return;
          //   }else{
          //     console.log('提交');
          //     // that.isok()
          //   }
          // };
          let flag = that.tabledata.every(item => !!item.buy_num)
          if (!flag) {
            api.toast({
                msg: '请填写叫货量',
                duration: 3000,
                location: 'bottom'
            });
            return;
          }else{
            that.isok()
          }
        },
        //提交
        isok:function(){
          let that=this;
          console.log(that.cardsmonth);
          if(that.isclick){
            that.isclick = false
            api.ajax({
              url:baseurl+'api/material/addOrder?sec=' + $api.getStorage('apptoken') + '&wsid=' + that.tabsid + '&date=' + that.cardsmonth,
              method:'post',
              data:{
                values:{
                  num_json:that.tabledata
                }
              }
            },function(ret,err){
              if(ret){
                api.hideProgress();
                console.log(JSON.stringify(ret));
                if(ret.status == 1){
                  api.toast({
                      msg: ret.msg,
                      duration: 3000,
                      location: 'bottom'
                  });
                  api.sendEvent({
                      name: 'materialorderok',
                      extra: {
                          key1: 'value1',
                          key2: 'value2'
                      }
                  });
                  setTimeout(function(){
                    api.closeWin()
                  },1500)
                }else{
                  api.toast({
                      msg: ret.msg,
                      duration: 3000,
                      location: 'bottom'
                  });
                }
              }else{
                api.hideProgress();
                console.log(JSON.stringify(err));
                api.toast({
                    msg: err.msg,
                    duration: 3000,
                    location: 'bottom'
                });
              }
            })
          }
          
        },
        //点击列
        gotrainpro:function(val){
          // console.log(JSON.stringify(val));
          // api.openWin({
          //     name: 'intraindesc',
          //     url: './intraindesc.html',
          //     pageParam: {
          //         id: val.id,
          //         levelid:val.up_levelid
          //     }
          // });
        },
       //表格data
        gettrainadmin:function(){
          let that=this;
          api.ajax({
            url:baseurl+'api/material/orderView',
            methods:'get',
            data:{
              values:{
                sec: $api.getStorage('apptoken'),
                wsid:that.tabsid,
                date:that.cardsmonth
              }
            }
          },function(ret,err){
            if(ret){
              api.hideProgress();
              console.log(JSON.stringify(ret));
              if(ret.status == 1){
                  
                that.tabledata = ret.data.list;
                that.askname = ret.data.buy_username;

              }else{
                api.toast({
                    msg: ret.msg,
                    duration: 3000,
                    location: 'bottom'
                });
              }
            }else{
              api.hideProgress();
              console.log(JSON.stringify(err));
              api.toast({
                  msg: err.msg,
                  duration: 3000,
                  location: 'bottom'
              });
            }
          })
        },
      }
    })
	}

	</script>
</body>
</html>
